package top.yaofengqiao.springcloudsimple.demo.biz.trigger.listener;

import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Service;
import top.yaofengqiao.springcloudsimple.common.constant.MQConstant;
import top.yaofengqiao.springcloudsimple.demo.biz.domain.order.service.IOrderService;
import top.yaofengqiao.springcloudsimple.demo.biz.trigger.listener.dto.OrderDeliverDTO;

import javax.annotation.Resource;

/**
 * @author yfq
 * @date 2024/6/19 9:27
 * @description 订单发货监听，需要保证幂等性
 */
@Slf4j
@Service
@RocketMQMessageListener(topic = MQConstant.ORDER_NORMAL_TOPIC,
        consumerGroup = MQConstant.ORDER_GROUP,
        selectorExpression = MQConstant.ORDER_DELIVER_TAG)
public class OrderDeliverListener implements RocketMQListener<OrderDeliverDTO> {
    @Resource
    private IOrderService orderService;

    @Override
    public void onMessage(OrderDeliverDTO orderDeliverDTO) {
        log.info("接收到订单发货消息：{}", JSON.toJSONString(orderDeliverDTO));
        orderService.orderDeliver(orderDeliverDTO);
    }

}
